/* 
** (Copyright) sejishikong <sejishikong@263.net>
** Authors:    sejishikong <sejishikong@263.net>
**             Wei Lian <lianwei3@gmail.com> 
** Maintainer: Wei Lian
**    This program is free software; you can redistribute it and/or modify
**    it under the terms of the GNU General Public License Version 2 as
**    published by the Free Software Foundation;
**
**    This program is distributed in the hope that it will be useful,
**    but WITHOUT ANY WARRANTY; without even the implied warranty of
**    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**    GNU General Public License for more details.
**
**    You should have received a copy of the GNU General Public License
**    along with this program; if not, write to the Free Software
**    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
*/

#include "config.h"
#include "header.h"

Config::Config(QWidget * parent, const char *name):QVBox(parent, name,
							 WType_Dialog)
{
    QSettings settings;


    QHBox *hbox = new QHBox(this);
    QLabel *label = new QLabel(tr("Player(mp3):"), hbox);
    editplayer_mp3 =
	new QLineEdit(settings.
		      readEntry("/qsopcast/player_mp3", "xmms"), hbox);
    hbox = new QHBox(this);
    label = new QLabel(tr("Player(rm):"), hbox);
    editplayer_rm =
	new QLineEdit(settings.
		      readEntry("/qsopcast/player_rm",
				"mplayer -ontop -geometry 100%:100%"),
		      hbox);
    hbox = new QHBox(this);
    label = new QLabel(tr("Player(wmv):"), hbox);
    editplayer_wmv =
	new QLineEdit(settings.
		      readEntry("/qsopcast/player_wmv",
				"mplayer -ontop -geometry 100%:100%"),
		      hbox);


    hbox = new QHBox(this);
    label = new QLabel(tr("Channels url:"), hbox);
    editchannelurl =
	new QLineEdit(settings.
		      readEntry("/qsopcast/channelurl",
				"http://channel.sopcast.com/gchlxml"),
		      hbox);

    hbox = new QHBox(this);
    label = new QLabel(tr("Channels url header:"), hbox);
    editchannelheader =
	new QLineEdit(settings.
		      readEntry("/qsopcast/channelheader", "sop://"),
		      hbox);
    editchannelheader->setReadOnly(TRUE);

    hbox = new QHBox(this);
    label = new QLabel(tr("Record directory:"), hbox);
    editrecorddir =
	new QLineEdit(settings.
		      readEntry("/qsopcast/recorddir",
				QDir::homeDirPath() + "/SOPCAST/"), hbox);

    hbox = new QHBox(this);
    QPushButton *buttonsave = new QPushButton(tr("Save"), hbox);
    QPushButton *buttonclose = new QPushButton(tr("Close"), hbox);
    connect(buttonclose, SIGNAL(clicked()), this, SLOT(close()));
    connect(buttonsave, SIGNAL(clicked()), this,
	    SLOT(onbuttonsaveclicked()));

    adjustSize();
    setMinimumWidth(300);

}

void
 Config::onbuttonsaveclicked()
{
    QSettings settings;
    settings.writeEntry("/qsopcast/player_mp3", editplayer_mp3->text());
    settings.writeEntry("/qsopcast/player_rm", editplayer_rm->text());
    settings.writeEntry("/qsopcast/player_wmv", editplayer_wmv->text());
    settings.writeEntry("/qsopcast/channelurl", editchannelurl->text());
    settings.writeEntry("/qsopcast/channelheader",
			editchannelheader->text());
    settings.writeEntry("/qsopcast/recorddir", editrecorddir->text());

    close();
}
